<?php

namespace App\Core;

use App\Util\ArrayHelper;

abstract class DataSetBase{
    
    protected $data;
    
    public function __construct(array $data){
        $this->data = $data;
    }
    
    public function get($name, $default = null){
        return ArrayHelper::getValue($this->data, $name, $default);
    }
    
    public function set($name, $value){
        $this->data[$name] = $value;
        return $this;
    }
    
    public function has($name){
        return isset($this->data[$name]);
    }
    
    public function setItems($items){
        foreach($items as $k => $v){
            $this->set($k, $v);
        }
        return $this;
    }
    
    public function __get($name){
        return $this->get($name);
    }
    
    public function __set($name, $value){
        $this->set($name, $value);
    }
    
    public function all(){
        return $this->data;
    }
    
    public function __toString(){
        return json_encode($this->data, JSON_UNESCAPED_UNICODE);
    }
    
}